/*
 * @Author: steven.wang
 * @Date:   2019-03-14 10:59:29
 * @Last Modified by:   steven.wang
 * @Last Modified time: 2019-05-15 13:18:58
 */
const jwt = require('jsonwebtoken');
const secret = require('../config').secret;

/**
 * 获取jwt
 * @author steven.wang
 * @DateTime 2019-05-08T16:06:07+0800
 */
exports.getJwtPayload = token => {
    return new Promise((resolve, reject) => {
        jwt.verify(token, secret, function(err, data) {
            if (!err) {
                resolve(data)
            } else {
                reject(err)
            }
        })
    });
}
/**
 * 格式化接口返回
 * @author steven.wang
 * @DateTime 2019-05-08T16:09:00+0800
 */
exports.jsonSendFormat = (code, data) => {
	return {
		code: code,
		msg: code == 200 ? 'success' : data,
		data: code == 200 ? data : null,
	};
}